<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/template.xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core">
    
    <ui:define name="title"></ui:define>
    <ui:define name="content">
        <!-- <c:if test="#{userBean.currentUser.role == 'ADMIN'}"> -->
        
        <div id="adminmenu">
              <ui:include src="./menu.xhtml"></ui:include> 
        </div>
        <h3>Пользователи системы</h3>
           <div id="dataM">
        <div class="dataExport">
            <h:form>  
            <h:panelGrid columns="2">  
                <p:panel header="Експортировать все данные">  
                    <h:commandLink>  
                        <p:graphicImage value="/img/xls.png" />  
                        <p:dataExporter type="xls" target=":userList:allUsers" fileName="users" />  
                    </h:commandLink>  

                    <h:commandLink>  
                        <p:graphicImage value="/img/file_pdf.png" />  
                        <p:dataExporter type="pdf" target=":userList:allUsers" fileName="users"/>  
                    </h:commandLink>  

                    <h:commandLink>  
                        <p:graphicImage value="/img/csv_text.png" />  
                        <p:dataExporter type="csv" target=":userList:allUsers" fileName="users" />  
                    </h:commandLink>  

                    <h:commandLink>  
                        <p:graphicImage value="/img/file_xml.png" />  
                        <p:dataExporter type="xml" target=":userList:allUsers" fileName="users" />  
                    </h:commandLink>  
                </p:panel>  
                
                
            </h:panelGrid>    
           </h:form>
         </div>
            
        
        <div class="btnRight"><p:commandButton id="basic" value="Добавить пользователя" onclick="dlg.show();" type="button" />                               
            <p:dialog width="840" header="Создание нового пользователя" widgetVar="dlg" maximizable="true" minimizable="true">  
            <h:form prependId="false">
                <p:scrollPanel id="scp" style="width:780px;height:500px;padding: 15px;">
                <h:panelGrid columns="2" columnClasses="column" cellpadding="5"> 
                    <h:outputText value="Фамилия:"/>
                    <p:inputText value="#{userBean.newUser.surname}" />
                     <h:outputText value="Имя"/>
                     <p:inputText value="#{userBean.newUser.name}" />
                     <h:outputText value="Отчество:"/>
                     <p:inputText value="#{userBean.newUser.patronymic}" />
                     <h:outputText value="Дата рождения:"/>
                    <p:calendar navigator="true" value="#{userBean.newUser.birthday}"  />
                    
                     <h:outputText value="Email:"/>
                     <p:inputText value="#{userBean.newUser.email}" >
                        
                     </p:inputText>   
                           
                     <h:outputText value="Телефон:"/>
                     <p:inputText value="#{userBean.newUser.phone}" />
                     <h:outputText value="Категория:"/>
                     <h:selectOneMenu value="#{userBean.newUser.category}">
                                    <f:selectItems value="#{userBean.category}"
                                                   var="category"
                                                   itemLabel="#{category}"
                                                   itemValue="#{category}"
                                                   >
                                    </f:selectItems>
                                </h:selectOneMenu>
                     <h:outputText  value="Инфомация о пользователе:"/>
                     <p:inputTextarea cols="70" value="#{userBean.newUser.info}" />
                     <h:outputText value="Статус:"/>
                     <p:inputText value="#{userBean.newUser.status}" />
                     <h:outputText value="Роль:"/>
                     <h:selectOneMenu value="#{userBean.newUser.role}">
                                    <f:selectItems value="#{userBean.role}"
                                                   var="role"
                                                   itemLabel="#{role}"
                                                   itemValue="#{role}"
                                                   >
                                    </f:selectItems>
                                </h:selectOneMenu>
                     <h:outputText value="Пароль:"/>
                     <p:inputText value="#{userBean.newUser.password}" />
                </h:panelGrid>
                <p:growl id="growlPassport" showDetail="true"/>
                <p:fieldset legend="Паспортные данные"  style="margin: 10px;" toggleable="true" collapsed="false" toggleSpeed="500">
                    <p:ajax event="toggle" listener="#{userBean.handlePassportToggle}" update="growlPassport" />
                    <h:panelGrid columns="2" id="dataPassport" >
                        <h:outputText value="Номер паспорта"/>
                        <p:inputText value="#{userBean.userPassport.numberPassport}"/>
                        <h:outputText value="Дата выдачи"/>
                        <p:calendar navigator="true" value="#{userBean.userPassport.dateOfIssue}"/>
                        <h:outputText value="Информация"/>
                        <p:inputTextarea cols="70" value="#{userBean.userPassport.info}"/>
                    
                    </h:panelGrid>
                </p:fieldset>
                
                <p:fieldset legend="Данные о визе"  style="margin: 10px;" toggleable="true" collapsed="false" toggleSpeed="500">
                    <p:ajax event="toggle" update="growlPassport" />
                    <h:panelGrid columns="2" >
                        <h:outputText value="Номер паспорта по которому выдана виза"/>
                        <p:inputText id="counter" value="#{userBean.numberUserPassport}">  
                             <p:ajax event="keyup"  listener="#{userBean.findUserPassport}"/>                   
                        </p:inputText>  
                            <h:outputText value="Дата начала"/>
                            <p:calendar navigator="true" value="#{userBean.userVisa.dateBegin}"/>
                            <h:outputText value="Дата  окончания"/>
                            <p:calendar navigator="true" value="#{userBean.userVisa.dateEnd}"/>
                            <h:outputText value="Дата выдачи"/>
                            <p:calendar navigator="true" value="#{userBean.userVisa.dateOfIssue}"/>
                            <h:outputText value="Место выдачи"/>
                            <p:inputText value="#{userBean.userVisa.placeOfIssue}"/>
                            <h:outputText value="Тип визы"/>
                            <p:inputText value="#{userBean.userVisa.typeVisa}"/>
                    
                    
                    </h:panelGrid>
                </p:fieldset>
                
                 <p:messages id="messagesEmail" />  
                 <h:commandButton class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="Создать"   actionListener="#{userBean.saveUser}"/>
                 </p:scrollPanel>
            </h:form>
        </p:dialog>  
        </div>
           </div>
        <h:form id="userList" >
            
            <p:contextMenu for="allUsers">
                <p:menuitem value="Просмотреть" update="d,userOrdersList,userPassportList" icon="ui-icon-search" oncomplete="userDislay.show()"/>
                <p:menuitem value="Удалить" update="allUsers" icon="ui-icon-close" actionListener="#{userBean.deleteUser}"/>
            </p:contextMenu>
            
            <p:growl id="messages" showDetail="true"/>
            <p:dataTable var="user" value="#{userBean.allUsers}"  id="allUsers" rowKey="#{user.email}" 
                         selection="#{userBean.selectUser}" selectionMode="single"
                         >
                   <p:ajax event="rowEdit" listener="#{userBean.onEdit}" update=":userList:messages"/>
                   
                   <p:column headerText="Фамилия" sortBy="#{user.surname}" filterBy="#{user.surname}" style="width: 5%">
                        <h:outputText value="#{user.surname}"/>
                   </p:column> 
                   <p:column headerText="Имя" sortBy="#{user.name}" filterBy="#{user.name}" style="width: 5%">
                   <h:outputText value="#{user.name}"/>
                    </p:column>
                   <p:column headerText="Отчество" sortBy="#{user.patronymic}" filterBy="#{user.patronymic}" style="width: 5%">
                    <h:outputText value="#{user.patronymic}"/>
                    </p:column>
                   <p:column headerText="Email" sortBy="#{user.email}" filterBy="#{user.email}" style="width: 10%">
                   <h:outputText value="#{user.email}"/>
                    </p:column>
                   <p:column headerText="Телефон" sortBy="#{user.phone}" filterBy="#{user.phone}"  style="width: 10%">
                   <h:outputText value="#{user.phone}"/>
                   </p:column>         
                   <p:column headerText="Категория" sortBy="#{user.category}" filterBy="#{user.category}">
                     
                               <h:outputText value="#{user.category}"/>
  
                    </p:column>
                    
                   <p:column headerText="Статус" sortBy="#{user.status}" filterBy="#{user.status}" style="width: 10%">                
                                <h:outputText value="#{user.status}"/>      
                    </p:column>
                    
                   <p:column headerText="Роль" sortBy="#{user.role}" filterBy="#{user.role}">                      
                                <h:outputText value="#{user.role}"/>
                    </p:column>
             </p:dataTable>  
               
                   <p:dialog header="Подробная информация о пользователе" widgetVar="userDislay" resizable="false"
                             width="800" showEffect="clips" modal="true" hideEffect="fold" id="d1">
                       <h:panelGrid id="d" columns="2">
                          <h:outputText value="Фамилия" />
                          <h:outputText value="#{userBean.selectUser.surname}" />
                          <h:outputText value="Имя" />
                          <h:outputText value="#{userBean.selectUser.name}" />
                          <h:outputText value="Отчество" />
                          <h:outputText value="#{userBean.selectUser.patronymic}" />
                          <h:outputText value="Дата рождения" />
                          <h:outputText value="#{userBean.selectUser.birthday}" />
                          <h:outputText value="Категория пользователя" />
                          <h:outputText value="#{userBean.selectUser.category}" />
                           <h:outputText value="Email" />
                           <h:outputText value="#{userBean.selectUser.email}" />
                           <h:outputText value="Телефон" />
                           <h:outputText value="#{userBean.selectUser.phone}" />
                           <h:outputText value="Роль" />
                           <h:outputText value="#{userBean.selectUser.role}" />
                           <h:outputText value="Статус" />
                           <h:outputText value="#{userBean.selectUser.status}" />
                           <h:outputText value="Информация" />
                           <h:outputText value="#{userBean.selectUser.info}" />
                           
                       </h:panelGrid>
                       <p:dataTable var="passport" id="userPassportList" value="#{userBean.selectUser.passportList}">
                           <p:column><h:outputText value="#{passport.numberPassport}"/></p:column> 
                           <p:column><h:outputText value="#{passport.dateOfIssue}"/></p:column>
                           <p:column><h:outputText value="#{passport.info}"/></p:column> 
                       </p:dataTable>
                       <h3>Список заказов пользователя</h3>
                       <p:dataGrid style="margin: 10px;" value="#{userBean.selectUser.ordersList}" var="orders" id="userOrdersList" 
                                   paginator="true" rows="5">
                           <p:commandButton icon="ui-icon-search"  oncomplete="userOrderDialog.show()" title="История заказа" >
                               <f:setPropertyActionListener value="#{orders}" target="#{userBean.selectUserOrder}" /> 
                           </p:commandButton>
                           <h:outputText value="#{orders.dateOrder.toGMTString()} На суму: #{orders.totalCost} грн."/>
                           
                       </p:dataGrid>
                       <p:dialog width="700" appendToBody="true" modal="false" header="История заказа пользователя" widgetVar="userOrderDialog">
                           
                       </p:dialog>
                        <p:commandButton value="Print" type="button" icon="ui-icon-print">  
                             <p:printer target="d" />  
                        </p:commandButton>  
                   </p:dialog>
        </h:form>
        
       <!-- </c:if> -->
    </ui:define>
</ui:composition>
